<!doctype html>
<html>
<head>
	<meta charset="utf-8">
	<title>表单验证 | Laravel 5.2 中文文档
</title>
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="author" content="Taylor Otwell">
	<meta name="description" content="表单验证,简介,验证快速上手,定义路由,创建控制器,编写验证逻辑,显示验证错误,AJAX 请求和验证,验证 Arrays,其它验证的处理,手动创建验证程序,表单要求验证,处理错误消息,自定义错误消息,可用的验证规则,按条件增加...
">
	<meta name="keywords" content="laravel,laravel中国,laravel中文,laravel框架中文,laravel文档,laravel框架中国,laravel中文文档">
	<meta name="viewport" content="width=device-width, initial-scale=1">
			<link rel="canonical" href="../5.4/validation.html" />
		<!--[if lte IE 9]>
		<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
	<![endif]-->
	<link rel="stylesheet" href="../../build/assets/css/laravel-3d54d47ea3.css">
	<link rel="apple-touch-icon" href="../../favicon.png.jpeg">
</head>
<body class="docs language-php">

	<span class="overlay"></span>

	<nav class="main">
		<a href="../../index.html" class="brand nav-block">
			<svg version="1.1"
	 xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:a="http://ns.adobe.com/AdobeSVGViewerExtensions/3.0/"
	 x="0px" y="0px" width="84.1px" height="57.6px" viewBox="0 0 84.1 57.6" enable-background="new 0 0 84.1 57.6"
	 xml:space="preserve">
<defs>
</defs>
<path fill="#FB503B" d="M83.8,26.9c-0.6-0.6-8.3-10.3-9.6-11.9c-1.4-1.6-2-1.3-2.9-1.2s-10.6,1.8-11.7,1.9c-1.1,0.2-1.8,0.6-1.1,1.6
	c0.6,0.9,7,9.9,8.4,12l-25.5,6.1L21.2,1.5c-0.8-1.2-1-1.6-2.8-1.5C16.6,0.1,2.5,1.3,1.5,1.3c-1,0.1-2.1,0.5-1.1,2.9
	c1,2.4,17,36.8,17.4,37.8c0.4,1,1.6,2.6,4.3,2c2.8-0.7,12.4-3.2,17.7-4.6c2.8,5,8.4,15.2,9.5,16.7c1.4,2,2.4,1.6,4.5,1
	c1.7-0.5,26.2-9.3,27.3-9.8c1.1-0.5,1.8-0.8,1-1.9c-0.6-0.8-7-9.5-10.4-14c2.3-0.6,10.6-2.8,11.5-3.1C84.2,28,84.4,27.5,83.8,26.9z
	 M37.5,36.4c-0.3,0.1-14.6,3.5-15.3,3.7c-0.8,0.2-0.8,0.1-0.8-0.2C21.2,39.6,4.4,4.8,4.1,4.4c-0.2-0.4-0.2-0.8,0-0.8
	c0.2,0,13.5-1.2,13.9-1.2c0.5,0,0.4,0.1,0.6,0.4c0,0,18.7,32.3,19,32.8C38,36.1,37.8,36.3,37.5,36.4z M77.7,43.9
	c0.2,0.4,0.5,0.6-0.3,0.8c-0.7,0.3-24.1,8.2-24.6,8.4c-0.5,0.2-0.8,0.3-1.4-0.6s-8.2-14-8.2-14L68.1,32c0.6-0.2,0.8-0.3,1.2,0.3
	C69.7,33,77.5,43.6,77.7,43.9z M79.3,26.3c-0.6,0.1-9.7,2.4-9.7,2.4l-7.5-10.2c-0.2-0.3-0.4-0.6,0.1-0.7c0.5-0.1,9-1.6,9.4-1.7
	c0.4-0.1,0.7-0.2,1.2,0.5c0.5,0.6,6.9,8.8,7.2,9.1C80.3,26,79.9,26.2,79.3,26.3z"/>
</svg>

			<span>Laravel</span>
		</a>

        <div class="search nav-block">
            <svg version="1.1"
	 xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:a="http://ns.adobe.com/AdobeSVGViewerExtensions/3.0/"
	 x="0px" y="0px" width="16px" height="16px" viewBox="0 0 16 16" enable-background="new 0 0 16 16" xml:space="preserve">
<defs>
</defs>
<g>
	<g>
		<path fill="#A1A1A1" d="M5.8,11.7c-1.6,0-3-0.6-4.1-1.7S0,7.4,0,5.8s0.6-3,1.7-4.1C2.8,0.6,4.3,0,5.8,0s3,0.6,4.1,1.7
			c2.3,2.3,2.3,6,0,8.3C8.9,11.1,7.4,11.7,5.8,11.7z M5.8,1C4.5,1,3.3,1.5,2.4,2.4C1.5,3.3,1,4.5,1,5.8s0.5,2.5,1.4,3.4
			c0.9,0.9,2.1,1.4,3.4,1.4s2.5-0.5,3.4-1.4c1.9-1.9,1.9-5,0-6.9C8.4,1.5,7.1,1,5.8,1z"/>
	</g>
	<g>
		<path fill="#A1A1A1" d="M15.5,16c-0.1,0-0.3,0-0.3-0.1L9.3,10c-0.2-0.2-0.2-0.5,0-0.7s0.5-0.2,0.7,0l5.9,5.9
			c0.2,0.2,0.2,0.5,0,0.7C15.8,16,15.6,16,15.5,16z"/>
	</g>
</g>
</svg>

            <input placeholder="搜索文档" type="text" v-model="search" id="search-input" v-on:blur="reset" />
        </div>

		<ul class="main-nav" v-if="! search">
			<li class="nav-docs"><a href="../5.4.html">文档</a></li>
<li ><a href="https://news.laravel-china.org/" class="no-pjax">Laravel 资讯</a></li>
<li class="dropdown"><a href="https://laravel-china.org/">Laravel China 社区</a></li>
<li class="nav-forge"><a href="https://laravel-china.org/categories/1">酷工作</a></li>
<li class="nav-docs"><a href="http://lumen.laravel-china.org">Lumen</a></li>
<li class="nav-forge"><a href="https://cs.laravel-china.org/">速查表</a></li>
<li class="nav-forge"><a href="https://laravel-china.org/laravel-tutorial/5.1/about">《Laravel 入门教程》</a></li>
		</ul>

        			<div class="switcher">
	<div class="dropdown">
		<button class="btn dropdown-toggle btn-inverted" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-expanded="true">
			<!--<span class="faint">v</span> -->
			5.2
			<span class="caret"></span>
		</button>
		<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
							<li role="presentation">
					<a role="menuitem" tabindex="-1" href="../5.4/validation.html">5.4</a>
				</li>
							<li role="presentation">
					<a role="menuitem" tabindex="-1" href="../5.3/validation.html">5.3</a>
				</li>
							<li role="presentation">
					<a role="menuitem" tabindex="-1" href="validation.html">5.2</a>
				</li>
							<li role="presentation">
					<a role="menuitem" tabindex="-1" href="../5.1/validation.html">5.1</a>
				</li>
					</ul>
	</div>
</div>
		
        <div class="responsive-sidebar-nav">
			<a href="validation.html#" class="toggle-slide menu-link btn">&#9776;</a>
		</div>
	</nav>

	<nav id="slide-menu" class="slide-menu" role="navigation">

	<div class="brand">
		<a href="../../index.html">
			<img src="../../assets/img/laravel-logo-white.png" height="50">
		</a>
	</div>

	<ul class="slide-main-nav">
		<li><a href="../../index.html">Home</a></li>
		<li class="nav-docs"><a href="../5.4.html">文档</a></li>
<li ><a href="https://news.laravel-china.org/" class="no-pjax">Laravel 资讯</a></li>
<li class="dropdown"><a href="https://laravel-china.org/">Laravel China 社区</a></li>
<li class="nav-forge"><a href="https://laravel-china.org/categories/1">酷工作</a></li>
<li class="nav-docs"><a href="http://lumen.laravel-china.org">Lumen</a></li>
<li class="nav-forge"><a href="https://cs.laravel-china.org/">速查表</a></li>
<li class="nav-forge"><a href="https://laravel-china.org/laravel-tutorial/5.1/about">《Laravel 入门教程》</a></li>
	</ul>

	<div class="slide-docs-nav">
		<h2>Documentation</h2>
		<ul>
<li>前言
<ul>
<li><a href="about.html">翻译说明</a></li>
<li><a href="releases.html">发行说明</a></li>
<li><a href="upgrade.html">升级导引</a></li>
<li><a href="contributions.html">贡献导引</a></li>
<li><a href="../../api/5.2/index.html">API 文档</a></li>
</ul></li>
<li>安装与配置
<ul>
<li><a href="installation.html">安装</a></li>
<li><a href="configuration.html">配置</a></li>
<li><a href="homestead.html">Homestead</a></li>
<li><a href="valet.html">Valet</a></li>
</ul></li>
<li>教程
<ul>
<li><a href="quickstart.html">初级任务清单</a></li>
<li><a href="quickstart-intermediate.html">中级任务清单</a></li>
</ul></li>
<li>基本功能
<ul>
<li><a href="routing.html">路由</a></li>
<li><a href="middleware.html">中间件</a></li>
<li><a href="controllers.html">控制器</a></li>
<li><a href="requests.html">请求</a></li>
<li><a href="responses.html">响应</a></li>
<li><a href="views.html">视图</a></li>
<li><a href="blade.html">Blade 模板</a></li>
</ul></li>
<li>系统架构
<ul>
<li><a href="lifecycle.html">请求生命周期</a></li>
<li><a href="structure.html">应用程序架构</a></li>
<li><a href="providers.html">服务提供者</a></li>
<li><a href="container.html">服务容器</a></li>
<li><a href="contracts.html">Contracts</a></li>
<li><a href="facades.html">Facades</a></li>
</ul></li>
<li>系统服务
<ul>
<li><a href="authentication.html">用户认证</a></li>
<li><a href="authorization.html">用户授权</a></li>
<li><a href="artisan.html">Artisan 命令行</a></li>
<li><a href="billing.html">交易</a></li>
<li><a href="cache.html">缓存</a></li>
<li><a href="collections.html">集合</a></li>
<li><a href="elixir.html">Elixir</a></li>
<li><a href="encryption.html">加密与解密</a></li>
<li><a href="errors.html">错误与日志</a></li>
<li><a href="events.html">事件</a></li>
<li><a href="filesystem.html">文件系统与云存储</a></li>
<li><a href="hashing.html">哈希</a></li>
<li><a href="helpers.html">辅助函数</a></li>
<li><a href="localization.html">本地化</a></li>
<li><a href="mail.html">邮件</a></li>
<li><a href="packages.html">扩展包开发</a></li>
<li><a href="pagination.html">分页</a></li>
<li><a href="queues.html">队列</a></li>
<li><a href="redis.html">Redis</a></li>
<li><a href="session.html">Session</a></li>
<li><a href="envoy.html">Envoy</a></li>
<li><a href="scheduling.html">任务调度</a></li>
<li><a href="testing.html">测试</a></li>
<li><a href="validation.html">表单验证</a></li>
</ul></li>
<li>数据库
<ul>
<li><a href="database.html">数据库入门</a></li>
<li><a href="queries.html">查询构造器</a></li>
<li><a href="migrations.html">数据库迁移</a></li>
<li><a href="seeding.html">数据填充</a></li>
</ul></li>
<li>Eloquent ORM
<ul>
<li><a href="eloquent.html">入门</a></li>
<li><a href="eloquent-relationships.html">模型关联</a></li>
<li><a href="eloquent-collections.html">Eloquent 集合</a></li>
<li><a href="eloquent-mutators.html">修改器</a></li>
<li><a href="eloquent-serialization.html">序列化</a></li>
</ul></li>
</ul>
	</div>

</nav>

<div class="docs-wrapper container">

	<section class="sidebar">

            <div class="header">
              <a type="button" class="btn btn-primary btn-inverted btn-lg btn-block turnofflight"><i class="fa fa-lightbulb-o"></i> 夜间模式 </a>
              <br>
              <div class="versions text-center ">
                <a class="doc-btn btn-inverted " href="../5.4.html" title="Laravel 5.4 中文文档">C5.4</a>
                <a class="doc-btn btn-inverted " href="../5.3.html" title="Laravel 5.3 中文文档">C5.3</a>
                <a class="doc-btn btn-inverted " href="../5.1.html" title="Laravel 5.1 中文文档">C5.1</a>
              </div>
            </div>

            <a href="https://laravel-china.org/topics/3383" target="_blank" rel="nofollow" title="" style="display: block;margin-bottom: 23px;">
                <img src="https://dn-phphub.qbox.me/uploads/images/201612/10/1/k7wwMpJduq.jpg" style="width: 100%;border: 1px solid #d8d3d3;box-shadow: 0 0 30px #d4d4d4;-moz-box-shadow: 0 0 30px #ccc;-webkit-box-shadow: 0 0 30px #d4d4d4;margin-bottom: 30px;margin-top: 10px;border-radius: 4px;">
            </a>

		<ul>
<li>前言
<ul>
<li><a href="about.html">翻译说明</a></li>
<li><a href="releases.html">发行说明</a></li>
<li><a href="upgrade.html">升级导引</a></li>
<li><a href="contributions.html">贡献导引</a></li>
<li><a href="../../api/5.2/index.html">API 文档</a></li>
</ul></li>
<li>安装与配置
<ul>
<li><a href="installation.html">安装</a></li>
<li><a href="configuration.html">配置</a></li>
<li><a href="homestead.html">Homestead</a></li>
<li><a href="valet.html">Valet</a></li>
</ul></li>
<li>教程
<ul>
<li><a href="quickstart.html">初级任务清单</a></li>
<li><a href="quickstart-intermediate.html">中级任务清单</a></li>
</ul></li>
<li>基本功能
<ul>
<li><a href="routing.html">路由</a></li>
<li><a href="middleware.html">中间件</a></li>
<li><a href="controllers.html">控制器</a></li>
<li><a href="requests.html">请求</a></li>
<li><a href="responses.html">响应</a></li>
<li><a href="views.html">视图</a></li>
<li><a href="blade.html">Blade 模板</a></li>
</ul></li>
<li>系统架构
<ul>
<li><a href="lifecycle.html">请求生命周期</a></li>
<li><a href="structure.html">应用程序架构</a></li>
<li><a href="providers.html">服务提供者</a></li>
<li><a href="container.html">服务容器</a></li>
<li><a href="contracts.html">Contracts</a></li>
<li><a href="facades.html">Facades</a></li>
</ul></li>
<li>系统服务
<ul>
<li><a href="authentication.html">用户认证</a></li>
<li><a href="authorization.html">用户授权</a></li>
<li><a href="artisan.html">Artisan 命令行</a></li>
<li><a href="billing.html">交易</a></li>
<li><a href="cache.html">缓存</a></li>
<li><a href="collections.html">集合</a></li>
<li><a href="elixir.html">Elixir</a></li>
<li><a href="encryption.html">加密与解密</a></li>
<li><a href="errors.html">错误与日志</a></li>
<li><a href="events.html">事件</a></li>
<li><a href="filesystem.html">文件系统与云存储</a></li>
<li><a href="hashing.html">哈希</a></li>
<li><a href="helpers.html">辅助函数</a></li>
<li><a href="localization.html">本地化</a></li>
<li><a href="mail.html">邮件</a></li>
<li><a href="packages.html">扩展包开发</a></li>
<li><a href="pagination.html">分页</a></li>
<li><a href="queues.html">队列</a></li>
<li><a href="redis.html">Redis</a></li>
<li><a href="session.html">Session</a></li>
<li><a href="envoy.html">Envoy</a></li>
<li><a href="scheduling.html">任务调度</a></li>
<li><a href="testing.html">测试</a></li>
<li><a href="validation.html">表单验证</a></li>
</ul></li>
<li>数据库
<ul>
<li><a href="database.html">数据库入门</a></li>
<li><a href="queries.html">查询构造器</a></li>
<li><a href="migrations.html">数据库迁移</a></li>
<li><a href="seeding.html">数据填充</a></li>
</ul></li>
<li>Eloquent ORM
<ul>
<li><a href="eloquent.html">入门</a></li>
<li><a href="eloquent-relationships.html">模型关联</a></li>
<li><a href="eloquent-collections.html">Eloquent 集合</a></li>
<li><a href="eloquent-mutators.html">修改器</a></li>
<li><a href="eloquent-serialization.html">序列化</a></li>
</ul></li>
</ul>

		<hr>
            <ul>
              <li>社交账号
                <ul>
                  <li><a href="http://weibo.com/laravelnews">微博：「Laravel资讯」</a></li>
                  <li>
                    新手 QQ 群：483184286
                  </li>
                  <li>
                    <br>
                    订阅 Laravel 资讯
<img class="image-border popover-with-html" data-content="" src="https://dn-phphub.qbox.me/uploads/images/201609/19/1/pVYzokV0Od.jpg" style="width: 148px;height: 148px;border:1px solid #ccc;padding:2px;border-radius:3px;margin-top:5px;" data-original-title="" title="">
                  </li>

                </ul>
              </li>
            </ul>

	</section>

	

	<article>

		<div class="alert alert-warning" role="alert">
			一小时同步一次，更多信息请查阅 <a href="https://laravel-china.org/topics/2095">文档导读</a>。
			发现瑕疵？你也可以
				<a href="https://github.com/laravel-china/laravel-docs/edit/5.2/validation.md"><i class="fa fa-pencil-square-o"></i> 改进本文</a>
			。
		</div>

		<div class="main-content">
			<h1>表单验证</h1>
<ul>
<li><a href="validation.html#introduction">简介</a></li>
<li><a href="validation.html#validation-quickstart">验证快速上手</a>
<ul>
<li><a href="validation.html#quick-defining-the-routes">定义路由</a></li>
<li><a href="validation.html#quick-creating-the-controller">创建控制器</a></li>
<li><a href="validation.html#quick-writing-the-validation-logic">编写验证逻辑</a></li>
<li><a href="validation.html#quick-displaying-the-validation-errors">显示验证错误</a></li>
<li><a href="validation.html#quick-ajax-requests-and-validation">AJAX 请求和验证</a></li>
<li><a href="validation.html#validating-arrays">验证 Arrays</a></li>
</ul></li>
<li><a href="validation.html#other-validation-approaches">其它验证的处理</a>
<ul>
<li><a href="validation.html#manually-creating-validators">手动创建验证程序</a></li>
<li><a href="validation.html#form-request-validation">表单要求验证</a></li>
</ul></li>
<li><a href="validation.html#working-with-error-messages">处理错误消息</a>
<ul>
<li><a href="validation.html#custom-error-messages">自定义错误消息</a></li>
</ul></li>
<li><a href="validation.html#available-validation-rules">可用的验证规则</a></li>
<li><a href="validation.html#conditionally-adding-rules">按条件增加规则</a></li>
<li><a href="validation.html#custom-validation-rules">自定义验证规则</a></li>
</ul>
<p><a name="introduction"></a></p>
<h2>简介</h2>
<p>Laravel 提供了多种不同的处理方法来对应用程序传入的数据进行验证。默认情况下，Laravel 的基底控制器类使用了 <code>ValidatesRequests</code> trait，其提供了一种便利的方法来使用各种强大的验证规则验证传入的 HTTP 请求。</p>
<p><a name="validation-quickstart"></a></p>
<h2>验证快速上手</h2>
<p>要了解 Laravel 相关的强大验证特色，先让我们来看看一个完整的表单验证示例以及返回错误消息给用户。</p>
<p><a name="quick-defining-the-routes"></a></p>
<h4>定义路由</h4>
<p>首先，我们假设在 <code>app/Http/routes.php</code> 文件中定义了以下路由：</p>
<pre><code>// 显示一个创建博客文章的表单...
Route::get('post/create', 'PostController@create');

// 保存一个新的博客文章...
Route::post('post', 'PostController@store');</code></pre>
<p><code>GET</code> 路由会显示一个用于创建新博客文章的表单，<code>POST</code> 路由则会将新的博客文章保存到数据库。</p>
<p><a name="quick-creating-the-controller"></a></p>
<h4>创建控制器</h4>
<p>接下来，让我们来看下操作这些路由的控制器。我们先让 <code>store</code> 方法空着：</p>
<pre><code>&lt;?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class PostController extends Controller
{
    /**
     * 显示创建博客文章的表单。
     *
     * @return Response
     */
    public function create()
    {
        return view('post.create');
    }

    /**
     * 保存一个新的博客文章。
     *
     * @param  Request  $request
     * @return Response
     */
    public function store(Request $request)
    {
        // 验证以及保存博客发表文章...
    }
}</code></pre>
<p><a name="quick-writing-the-validation-logic"></a></p>
<h4>编写验证逻辑</h4>
<p>现在我们准备开始填写我们的 <code>store</code> 逻辑方法来验证我们博客发布的新文章。检查应用程序的基底控制器 (<code>App\Http\Controllers\Controller</code>) 类你会看到这个类使用了 <code>ValidatesRequests</code> trait。这个 trait 在你所有的控制器里提供了方便的 <code>validate</code> 验证方法。</p>
<p><code>validate</code> 方法会接收 HTTP 传入的请求以及验证的规则。如果验证通过，你的代码就可以正常的运行。若验证失败，则会抛出异常错误消息并自动将其返回给用户。在一般的 HTTP 请求下，都会生成一个重定向响应，对于 AJAX 请求则会发送 JSON 响应。</p>
<p>让我们接着回到 <code>store</code> 方法来深入理解 <code>validate</code> 方法：</p>
<pre><code>/**
 * 保存一篇新的博客文章。
 *
 * @param  Request  $request
 * @return Response
 */
public function store(Request $request)
{
    $this-&gt;validate($request, [
        'title' =&gt; 'required|unique:posts|max:255',
        'body' =&gt; 'required',
    ]);

    // 博客文章成功发表，将其保存到数据库...
}</code></pre>
<p>如你所见，我们将本次 HTTP 请求及所需的验证规则传递至 <code>validate</code> 方法中。另外再提醒一次，如果验证失败，将会自动生成一个对应的响应。如果验证通过，那我们的控制器将会继续正常运行。</p>
<h4>对于嵌套属性的提醒</h4>
<p>如果你的 HTTP 请求中包含了「嵌套」参数，则可以在验证规则中使用「点」语法来指定他们：</p>
<pre><code>$this-&gt;validate($request, [
    'title' =&gt; 'required|unique:posts|max:255',
    'author.name' =&gt; 'required',
    'author.description' =&gt; 'required',
]);</code></pre>
<p><a name="quick-displaying-the-validation-errors"></a></p>
<h4>显示验证错误</h4>
<p>如果本次请求的参数未通过我们指定的验证规则呢？正如前面所提到的，Laravel 会自动把用户重定向到先前的位置。另外，所有的验证错误会被自动 <a href="session.html#flash-data">闪存至 session</a>。</p>
<p>请注意我们并不需要在 <code>GET</code> 路由中明确的将错误消息绑定到视图上。这是因为 Laravel 会自动检查 session 内的错误数据，如果错误存在的话，它会自动将这些错误消息绑定到视图上。<strong>因此需要的注意一点是 <code>$errors</code> 变量在每次请求的所有视图中都可以被使用</strong>，你可以很方便的假设 <code>$errors</code> 变量已被定义且进行安全地使用。<code>$errors</code> 变量是 <code>Illuminate\Support\MessageBag</code> 的实例。有关此对象的详细信息，<a href="validation.html#working-with-error-messages">请查阅它的文档</a>。</p>
<p>所以，在我们的例子中，当验证失败时，用户将被重定向到我们的控制器 <code>create</code> 方法，让我们在视图中显示错误的消息：</p>
<pre><code>&lt;!-- /resources/views/post/create.blade.php --&gt;

&lt;h1&gt;创建文章&lt;/h1&gt;

@if (count($errors) &gt; 0)
    &lt;div class="alert alert-danger"&gt;
        &lt;ul&gt;
            @foreach ($errors-&gt;all() as $error)
                &lt;li&gt;{{ $error }}&lt;/li&gt;
            @endforeach
        &lt;/ul&gt;
    &lt;/div&gt;
@endif

&lt;!-- 创建文章的表单 --&gt;</code></pre>
<p><a name="quick-customizing-the-flashed-error-format"></a></p>
<h4>自定义闪存的错误消息格式</h4>
<p>当验证失败时，如果你想要在闪存上自定义验证的错误格式，则需在控制器中重写 <code>formatValidationErrors</code>。别忘了将 <code>Illuminate\Contracts\Validation\Validator</code> 类引入到文件上方：</p>
<pre><code>&lt;?php

namespace App\Http\Controllers;

use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Contracts\Validation\Validator;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;

abstract class Controller extends BaseController
{
    use DispatchesJobs, ValidatesRequests;

    /**
     * {@inheritdoc}
     */
    protected function formatValidationErrors(Validator $validator)
    {
        return $validator-&gt;errors()-&gt;all();
    }
}</code></pre>
<p><a name="quick-ajax-requests-and-validation"></a></p>
<h3>AJAX 请求和验证</h3>
<p>在这个例子中，我们使用一种传统的方式来将数据发送到应用程序上。当我们在 AJAX 的请求中使用 <code>validate</code> 方法时，Laravel 并不会生成一个重定向响应，而是会生成一个包含所有错误验证的 JSON 响应。这个 JSON 响应会发送一个 422 HTTP 状态码。</p>
<p><a name="validating-arrays"></a></p>
<h3>验证数组</h3>
<p>要验证指定数组输入字段中的每一个 email 是否唯一，可以这么做：</p>
<pre><code>$validator = Validator::make($request-&gt;all(), [
    'person.*.email' =&gt; 'email|unique:users',
    'person.*.first_name' =&gt; 'required_with:person.*.last_name',
]);</code></pre>
<p>你可以使用 <code>*</code> 来自定义验证数组字段的错误消息提醒：</p>
<pre><code>'custom' =&gt; [
    'person.*.email' =&gt; [
        'unique' =&gt; 'Each person must have a unique e-mail address',
    ]
],</code></pre>
<p><a name="other-validation-approaches"></a></p>
<h2>其它验证的处理</h2>
<p><a name="manually-creating-validators"></a></p>
<h3>手动创建验证程序</h3>
<p>如果你不想要使用 <code>ValidatesRequests</code> trait 的 <code>validate</code> 方法，你可以手动创建一个 validator 实例并通过 <code>Validator::make</code> 方法在 <a href="facades.html">facade</a> 生成一个新的 validator 实例：</p>
<pre><code>&lt;?php

namespace App\Http\Controllers;

use Validator;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class PostController extends Controller
{
    /**
     * 保存一篇新的博客文章。
     *
     * @param  Request  $request
     * @return Response
     */
    public function store(Request $request)
    {
        $validator = Validator::make($request-&gt;all(), [
            'title' =&gt; 'required|unique:posts|max:255',
            'body' =&gt; 'required',
        ]);

        if ($validator-&gt;fails()) {
            return redirect('post/create')
                        -&gt;withErrors($validator)
                        -&gt;withInput();
        }

        // 保存文章...
    }
}</code></pre>
<p>第一个传给 <code>make</code> 方法的参数是验证数据。第二个参数则是数据的验证规则。</p>
<p>如果请求没有通过验证，则可以使用 <code>withErrors</code> 方法把错误消息闪存到 session。在进行重定向之后，<code>$errors</code> 变量可以在视图中自动共用，让你可以轻松地显示这些消息并返回给用户。<code>withErrors</code> 方法接收 validator、<code>MessageBag</code>，或 PHP <code>array</code>。</p>
<h4>命名错误清单</h4>
<p>假如在一个页面中有许多表单，你可能希望为 <code>MessageBag</code> 的错误命名，这可以让你获取特定表单的所有错误消息。只需在 <code>withErrors</code> 的第二个参数设置名称即可：</p>
<pre><code>return redirect('register')
            -&gt;withErrors($validator, 'login');</code></pre>
<p>然后你就可以从一个 <code>$errors</code> 变量中，获取已命名的 <code>MessageBag</code> 实例：</p>
<pre><code>{{ $errors-&gt;login-&gt;first('email') }}</code></pre>
<h4>验证后的挂勾</h4>
<p>在验证完成之后，validator 可以让你附加返回消息。你可以更简单的做进一步的验证以及增加更多的错误消息到消息集合上。在 validator 实例使用 <code>after</code> 方法如下所示：</p>
<pre><code>$validator = Validator::make(...);

$validator-&gt;after(function($validator) {
    if ($this-&gt;somethingElseIsInvalid()) {
        $validator-&gt;errors()-&gt;add('field', 'Something is wrong with this field!');
    }
});

if ($validator-&gt;fails()) {
    //
}</code></pre>
<p><a name="form-request-validation"></a></p>
<h3>表单请求验证</h3>
<p>在更复杂的验证情境中，你可能会想要创建一个「表单请求（ form request ）」。表单请求是一个自定义的请求类，里面包含着验证逻辑。要创建一个表单请求类，可使用 Artisan 命令行命令 <code>make:request</code> ：</p>
<pre><code>php artisan make:request StoreBlogPostRequest</code></pre>
<p>新生成的类文件会被放在 <code>app/Http/Requests</code> 目录下。让我们将一些验证规则加入到 <code>rules</code> 方法中：</p>
<pre><code>/**
 * 获取适用于请求的验证规则。
 *
 * @return array
 */
public function rules()
{
    return [
        'title' =&gt; 'required|unique:posts|max:255',
        'body' =&gt; 'required',
    ];
}</code></pre>
<p>怎样才能较好的运行验证规则呢？你所需要做的就是在控制器方法中利用类型提示传入请求。传入的请求会在控制器方法被调用前进行验证，意思就是说你不会因为验证逻辑而把控制器弄得一团糟：</p>
<pre><code>/**
 * 保存传入的博客文章。
 *
 * @param  StoreBlogPostRequest  $request
 * @return Response
 */
public function store(StoreBlogPostRequest $request)
{
    // 传入的请求是有效的...
}</code></pre>
<p>如果验证失败，就会生成一个重定向响应把用户返回到先前的位置。这些错误会被闪存到 session，所以这些错误都可以被显示。如果进来的是 AJAX 请求的话，则会传回一个 HTTP 响应，其中包含了 422 状态码和验证错误的 JSON 数据。</p>
<h4>授权表单请求</h4>
<p>表单的请求类内包含了 <code>authorize</code> 方法。在这个方法中，你可以确认用户是否真的通过了授权，以便更新指定数据。比方说，有一个用户想试图去更新一篇文章的评论，你能保证他确实是这篇评论的拥有者吗？具体代码如下：</p>
<pre><code>/**
 * 判断用户是否有权限做出此请求。
 *
 * @return bool
 */
public function authorize()
{
    $commentId = $this-&gt;route('comment');

    return Comment::where('id', $commentId)
                  -&gt;where('user_id', Auth::id())-&gt;exists();
}</code></pre>
<p>请注意，在上面例子中调用 <code>route</code> 方法。该方法可以帮助你获取路由被调用时传入的 URI 参数，如示例中的 <code>{comment}</code> 参数：</p>
<pre><code>Route::post('comment/{comment}');</code></pre>
<p>如果 <code>authorize</code> 方法返回 <code>false</code>，则会自动返回一个 HTTP 响应，其中包含 403 状态码，而你的控制器方法也将不会被运行。</p>
<p>如果你打算在应用程序的其它部分处理授权逻辑，只需从 <code>authorize</code> 方法返回 <code>true</code> ：</p>
<pre><code>/**
 * 判断用户是否有权限做出此请求。
 *
 * @return bool
 */
public function authorize()
{
    return true;
}</code></pre>
<h4>自定义闪存的错误消息格式</h4>
<p>如果你想要自定义验证失败时闪存到 session 的验证错误格式，可在你的基底请求 (<code>App\Http\Requests\Request</code>) 中重写 <code>formatErrors</code>。别忘了文件上方引入 <code>Illuminate\Contracts\Validation\Validator</code> 类：</p>
<pre><code>/**
 * {@inheritdoc}
 */
protected function formatErrors(Validator $validator)
{
    return $validator-&gt;errors()-&gt;all();
}</code></pre>
<h4>自定义错误消息</h4>
<p>你可以通过重写表单请求的 <code>messages</code> 方法来自定义错误消息。此方法必须返回一个数组，其中含有成对的属性或规则以及对应的错误消息：</p>
<pre><code>/**
 * 获取已定义验证规则的错误消息。
 *
 * @return array
 */
public function messages()
{
    return [
        'title.required' =&gt; '标题是必填的',
        'body.required'  =&gt; '消息是必填的',
    ];
}</code></pre>
<p><a name="working-with-error-messages"></a></p>
<h2>处理错误消息</h2>
<p>调用一个 <code>Validator</code> 实例的 <code>errors</code> 方法，会得到一个 <code>Illuminate\Support\MessageBag</code> 的实例，里面有许多可让你操作错误消息的便利方法。</p>
<h4>查看特定字段的第一个错误消息</h4>
<p>如果要查看特定字段的第一个错误消息，可以使用 <code>first</code> 方法：</p>
<pre><code>$messages = $validator-&gt;errors();

echo $messages-&gt;first('email');</code></pre>
<h4>查看特定字段的所有错误消息</h4>
<p>如果你想通过指定字段来简单的获取所有消息中的一个数组，则可以使用 <code>get</code> 方法：</p>
<pre><code>foreach ($messages-&gt;get('email') as $message) {
    //
}</code></pre>
<h4>查看所有字段的所有错误消息</h4>
<p>如果你想要得到所有字段的消息数组，则可以使用 <code>all</code> 方法：</p>
<pre><code>foreach ($messages-&gt;all() as $message) {
    //
}</code></pre>
<h4>判断特定字段是否含有错误消息</h4>
<pre><code>if ($messages-&gt;has('email')) {
    //
}</code></pre>
<h4>获取格式化后的错误消息</h4>
<pre><code>echo $messages-&gt;first('email', '&lt;p&gt;:message&lt;/p&gt;');</code></pre>
<h4>获取所有格式化后的错误消息</h4>
<pre><code>foreach ($messages-&gt;all('&lt;li&gt;:message&lt;/li&gt;') as $message) {
    //
}</code></pre>
<p><a name="custom-error-messages"></a></p>
<h3>自定义错误消息</h3>
<p>如果有需要的话，你也可以自定义错误的验证消息来取代默认的验证消息。有几种方法可以来自定义指定的消息。首先，你需要先通过传递三个参数到 <code>Validator::make</code> 方法来自定义验证消息：</p>
<pre><code>$messages = [
    'required' =&gt; ':attribute 的字段是必要的。',
];

$validator = Validator::make($input, $rules, $messages);</code></pre>
<p>在这个例子中，<code>:attribute</code> 占位符会被通过验证的字段实际名称所取代。除此之外，你还可以使用其它默认字段的验证消息。例如：</p>
<pre><code>$messages = [
    'same'    =&gt; ':attribute 和 :other 必须相同。',
    'size'    =&gt; ':attribute 必须是 :size。',
    'between' =&gt; ':attribute 必须介于 :min - :max。',
    'in'      =&gt; ':attribute 必须是以下的类型之一： :values。',
];</code></pre>
<h4>指定自定义消息到特定的属性</h4>
<p>有时候你可能想要对特定的字段来自定义错误消息。只需在属性名称后加上「.」符号和指定验证的规则即可：</p>
<pre><code>$messages = [
    'email.required' =&gt; '我们需要知道你的 e-mail 地址！',
];</code></pre>
<p><a name="localization"></a></p>
<h4>在语言包中自定义指定消息</h4>
<p>在许多情况下，你可能希望在语言包中被指定的特定属性自定义消息不被直接传到 <code>Validator</code> 上。因此你可以把消息加入到 <code>resources/lang/xx/validation.php</code> 语言包中的 <code>custom</code> 数组。</p>
<pre><code>'custom' =&gt; [
    'email' =&gt; [
        'required' =&gt; '我们需要知道你的 e-mail 地址！',
    ],
],</code></pre>
<p><a name="available-validation-rules"></a></p>
<h2>可用的验证规则</h2>
<p>以下是所有可用的验证规则清单与功能：</p>
<style>
    .collection-method-list > p {
        column-count: 3; -moz-column-count: 3; -webkit-column-count: 3;
        column-gap: 2em; -moz-column-gap: 2em; -webkit-column-gap: 2em;
    }

    .collection-method-list a {
        display: block;
    }
</style>
<div class="collection-method-list">
<p><a href="validation.html#rule-accepted">Accepted</a>
<a href="validation.html#rule-active-url">Active URL</a>
<a href="validation.html#rule-after">After (Date)</a>
<a href="validation.html#rule-alpha">Alpha</a>
<a href="validation.html#rule-alpha-dash">Alpha Dash</a>
<a href="validation.html#rule-alpha-num">Alpha Numeric</a>
<a href="validation.html#rule-array">Array</a>
<a href="validation.html#rule-before">Before (Date)</a>
<a href="validation.html#rule-between">Between</a>
<a href="validation.html#rule-boolean">Boolean</a>
<a href="validation.html#rule-confirmed">Confirmed</a>
<a href="validation.html#rule-date">Date</a>
<a href="validation.html#rule-date-format">Date Format</a>
<a href="validation.html#rule-different">Different</a>
<a href="validation.html#rule-digits">Digits</a>
<a href="validation.html#rule-digits-between">Digits Between</a>
<a href="validation.html#rule-dimensions">Dimensions (Image Files)</a>
<a href="validation.html#rule-distinct">Distinct</a>
<a href="validation.html#rule-email">E-Mail</a>
<a href="validation.html#rule-exists">Exists (Database)</a>
<a href="validation.html#rule-file">File</a>
<a href="validation.html#rule-filled">Filled</a>
<a href="validation.html#rule-image">Image (File)</a>
<a href="validation.html#rule-in">In</a>
<a href="validation.html#rule-in-array">In Array</a>
<a href="validation.html#rule-integer">Integer</a>
<a href="validation.html#rule-ip">IP Address</a>
<a href="validation.html#rule-json">JSON</a>
<a href="validation.html#rule-max">Max</a>
<a href="validation.html#rule-mimetypes">MIME Types</a>
<a href="validation.html#rule-mimes">MIME Type By File Extension</a>
<a href="validation.html#rule-min">Min</a>
<a href="validation.html#rule-not-in">Not In</a>
<a href="validation.html#rule-numeric">Numeric</a>
<a href="validation.html#rule-present">Present</a>
<a href="validation.html#rule-regex">Regular Expression</a>
<a href="validation.html#rule-required">Required</a>
<a href="validation.html#rule-required-if">Required If</a>
<a href="validation.html#rule-required-unless">Required Unless</a>
<a href="validation.html#rule-required-with">Required With</a>
<a href="validation.html#rule-required-with-all">Required With All</a>
<a href="validation.html#rule-required-without">Required Without</a>
<a href="validation.html#rule-required-without-all">Required Without All</a>
<a href="validation.html#rule-same">Same</a>
<a href="validation.html#rule-size">Size</a>
<a href="validation.html#rule-string">String</a>
<a href="validation.html#rule-timezone">Timezone</a>
<a href="validation.html#rule-unique">Unique (Database)</a>
<a href="validation.html#rule-url">URL</a></p>
</div>
<p><a name="rule-accepted"></a></p>
<h4>accepted</h4>
<p>验证字段值是否为 <em>yes</em>、<em>on</em>、<em>1</em>、或 <em>true</em>。这在确认「服务条款」是否同意时相当有用。</p>
<p><a name="rule-active-url"></a></p>
<h4>active_url</h4>
<p>验证字段值是否为一个有效的网址，会通过 PHP 的 <code>checkdnsrr</code> 函数来验证。</p>
<p><a name="rule-after"></a></p>
<h4>after:<em>date</em></h4>
<p>验证字段是否是在指定日期之后。这个日期将会通过 <code>strtotime</code> 函数来验证。</p>
<pre><code>'start_date' =&gt; 'required|date|after:tomorrow'</code></pre>
<p>作为替换 <code>strtotime</code> 传递的日期字符串，你可以指定其它的字段来比较日期：</p>
<pre><code>'finish_date' =&gt; 'required|date|after:start_date'</code></pre>
<p><a name="rule-alpha"></a></p>
<h4>alpha</h4>
<p>验证字段值是否仅包含字母字符。</p>
<p><a name="rule-alpha-dash"></a></p>
<h4>alpha_dash</h4>
<p>验证字段值是否仅包含字母、数字、破折号（ - ）以及下划线（ _ ）。</p>
<p><a name="rule-alpha-num"></a></p>
<h4>alpha_num</h4>
<p>验证字段值是否仅包含字母、数字。</p>
<p><a name="rule-array"></a></p>
<h4>array</h4>
<p>验证字段必须是一个 PHP <code>array</code>。</p>
<p><a name="rule-before"></a></p>
<h4>before:<em>date</em></h4>
<p>验证字段是否是在指定日期之前。这个日期将会使用 PHP <code>strtotime</code> 函数来验证。</p>
<p><a name="rule-between"></a></p>
<h4>between:<em>min</em>,<em>max</em></h4>
<p>验证字段值的大小是否介于指定的 <em>min</em> 和 <em>max</em> 之间。字符串、数值或是文件大小的计算方式和 <a href="validation.html#rule-size"><code>size</code></a> 规则相同。</p>
<p><a name="rule-boolean"></a></p>
<h4>boolean</h4>
<p>验证字段值是否能够转换为布尔值。可接受的参数为 <code>true</code>、<code>false</code>、<code>1</code>、<code>0</code>、<code>"1"</code> 以及 <code>"0"</code>。</p>
<p><a name="rule-confirmed"></a></p>
<h4>confirmed</h4>
<p>验证字段值必须和 <code>foo_confirmation</code> 的字段值一致。例如，如果要验证的字段是 <code>password</code>，就必须和输入数据里的 <code>password_confirmation</code> 的值保持一致。</p>
<p><a name="rule-date"></a></p>
<h4>date</h4>
<p>验证字段值是否为有效日期，会根据 PHP 的 <code>strtotime</code> 函数来做验证。</p>
<p><a name="rule-date-format"></a></p>
<h4>date_format:<em>format</em></h4>
<p>验证字段值符合定义的日期<em>格式</em>，通过 PHP 的 <code>date_parse_from_format</code> 函数来验证。</p>
<p><a name="rule-different"></a></p>
<h4>different:<em>field</em></h4>
<p>验证字段值是否和指定_字段（ field ）_不同。</p>
<p><a name="rule-digits"></a></p>
<h4>digits:<em>value</em></h4>
<p>验证字段值是否为 <em>numeric</em> 且长度为 <em>value</em>。</p>
<p><a name="rule-digits-between"></a></p>
<h4>digits_between:<em>min</em>,<em>max</em></h4>
<p>验证字段值的长度是否在 <em>min</em> 和 <em>max</em> 之间。</p>
<p><a name="rule-dimensions"></a></p>
<h4>dimensions</h4>
<p>验证的文件必须是图片并且图片比例必须符合规则：</p>
<pre><code>'avatar' =&gt; 'dimensions:min_width=100,min_height=200'</code></pre>
<p>可用的规则为： <em>min_width</em>, <em>max_width</em>, <em>min_height</em>, <em>max_height</em>, <em>width</em>, <em>height</em>, <em>ratio</em>。</p>
<p><a name="rule-distinct"></a></p>
<h4>distinct</h4>
<p>当你在验证数组的时候，你可以指定某个值必须是唯一的：</p>
<pre><code>'foo.*.id' =&gt; 'distinct'</code></pre>
<p><a name="rule-email"></a></p>
<h4>email</h4>
<p>验证字段值是否符合 e-mail 格式。</p>
<p><a name="rule-exists"></a></p>
<h4>exists:<em>table</em>,<em>column</em></h4>
<p>验证字段值是否存在指定的数据表中。</p>
<h4>Exists 规则的基本使用方法</h4>
<pre><code>'state' =&gt; 'exists:states'</code></pre>
<h4>指定一个特定的字段名称</h4>
<pre><code>'state' =&gt; 'exists:states,abbreviation'</code></pre>
<p>也可以指定更多的条件，它们会被加到「where」查询语句中：</p>
<pre><code>'email' =&gt; 'exists:staff,email,account_id,1'</code></pre>
<p>你也可以传递 <code>NULL</code> 或 <code>NOT_NULL</code> 至「where」语句：</p>
<pre><code>'email' =&gt; 'exists:staff,email,deleted_at,NULL'

'email' =&gt; 'exists:staff,email,deleted_at,NOT_NULL'</code></pre>
<p><a name="rule-file"></a></p>
<h4>file</h4>
<p>必须是上传的文件。</p>
<p><a name="rule-filled"></a></p>
<h4>filled</h4>
<p>验证的字段必须带有内容。</p>
<p><a name="rule-image"></a></p>
<h4>image</h4>
<p>验证字段文件必须为图片格式（ jpeg、png、bmp、gif、 或 svg ）。</p>
<p><a name="rule-in"></a></p>
<h4>in:<em>foo</em>,<em>bar</em>,...</h4>
<p>验证字段值是否有在指定的列表里面。</p>
<p><a name="rule-integer"></a></p>
<h4>integer</h4>
<p>验证字段值是否是整数。</p>
<p><a name="rule-ip"></a></p>
<h4>ip</h4>
<p>验证字段值是否符合 IP address 的格式。</p>
<p><a name="rule-json"></a></p>
<h4>json</h4>
<p>验证字段是否是一个有效的 JSON 字符串。</p>
<p><a name="rule-max"></a></p>
<h4>max:<em>value</em></h4>
<p>字段值必须小于或等于 <em>value</em> 。字符串、数值或是文件大小的计算方式和 <a href="validation.html#rule-size"><code>size</code></a> 规则相同。</p>
<p><a name="rule-mimetypes"></a></p>
<h4>mimetypes:<em>text/plain</em>,...</h4>
<p>验证的文件必须是这些 MIME 类型中的一个:</p>
<pre><code>'video' =&gt; 'mimetypes:video/avi,video/mpeg,video/quicktime'</code></pre>
<p>框架会通过阅读文件内容来推测 MIME 类型，有时候会与客户端的不一致。</p>
<p><a name="rule-mimes"></a></p>
<h4>mimes:<em>foo</em>,<em>bar</em>,...</h4>
<p>验证字段文件的 MIME 类型是否符合列表中指定的格式。</p>
<h4>MIME 规则基本用法</h4>
<pre><code>'photo' =&gt; 'mimes:jpeg,bmp,png'</code></pre>
<p>即使你可能只需要验证指定扩展名，但此规则实际上会验证文件的 MIME 类型，其通过读取文件的内容以猜测它的 MIME 类型。</p>
<p>完整的 MIME 类型及对应的扩展名列表可以在下方链接找到：
<a href="http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types"><a href="http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types">http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types</a></a></p>
<p><a name="rule-min"></a></p>
<h4>min:<em>value</em></h4>
<p>字段值必须大于或等于 <em>value</em>。字符串、数值或是文件大小的计算方式和 <a href="validation.html#rule-size"><code>size</code></a> 规则相同。</p>
<p><a name="rule-not-in"></a></p>
<h4>not_in:<em>foo</em>,<em>bar</em>,...</h4>
<p>验证字段值是否不在指定的列表里。</p>
<p><a name="rule-numeric"></a></p>
<h4>numeric</h4>
<p>验证字段值是否为数值。</p>
<p><a name="rule-present"></a></p>
<h4>present</h4>
<p>验证的字段必须出现，并且数据不为空。</p>
<p><a name="rule-regex"></a></p>
<h4>regex:<em>pattern</em></h4>
<p>验证字段值是否符合指定的正则表达式。</p>
<p><strong>注意：</strong>当使用 <code>regex</code> 规则时，你必须使用数组，而不是使用管道分隔规则，特别是当正则表达式含有管道符号时。</p>
<p><a name="rule-required"></a></p>
<h4>required</h4>
<p>验证字段必须存在输入数据，且不为空。字段符合下方任一条件时即为「空」：</p>
<ul>
<li>该值为 <code>null</code>。</li>
<li>该值为空字符串。</li>
<li>该值为空数组或空的<code>可数</code>对象。</li>
<li>该值为没有路径的上传文件。</li>
</ul>
<p><a name="rule-required-if"></a></p>
<h4>required_if:<em>anotherfield</em>,<em>value</em>,...</h4>
<p>如果指定的<em>其它字段</em>（ anotherfield ）等于任何一个 <em>value</em> 时，此字段为必填。</p>
<p><a name="rule-required-unless"></a></p>
<h4>required_unless:<em>anotherfield</em>,<em>value</em>,...</h4>
<p>如果指定的<em>其它字段</em>（ anotherfield ）等于任何一个 <em>value</em> 时，则此字段为不必填。</p>
<p><a name="rule-required-with"></a></p>
<h4>required_with:<em>foo</em>,<em>bar</em>,...</h4>
<p>如果指定的字段中的 <em>任意一个</em> 有值，则此字段为必填。</p>
<p><a name="rule-required-with-all"></a></p>
<h4>required_with_all:<em>foo</em>,<em>bar</em>,...</h4>
<p>如果指定的 <em>所有</em> 字段都有值，则此字段为必填。</p>
<p><a name="rule-required-without"></a></p>
<h4>required_without:<em>foo</em>,<em>bar</em>,...</h4>
<p>如果缺少任意一个指定的字段，则此字段为必填。</p>
<p><a name="rule-required-without-all"></a></p>
<h4>required_without_all:<em>foo</em>,<em>bar</em>,...</h4>
<p>如果所有指定的字段都没有值，则此字段为必填。</p>
<p><a name="rule-same"></a></p>
<h4>same:<em>field</em></h4>
<p>验证字段值和指定的 <em>字段（ field ）</em> 值是否相同。</p>
<p><a name="rule-size"></a></p>
<h4>size:<em>value</em></h4>
<p>验证字段值的大小是否符合指定的 <em>value</em> 值。对于字符串来说，<em>value</em> 为字符数。对于数字来说，<em>value</em> 为某个整数值。对文件来说，<em>size</em> 对应的是文件大小（单位 kb ）。</p>
<p><a name="rule-string"></a></p>
<h4>string</h4>
<p>验证字段值的类型是否为字符串。</p>
<p><a name="rule-timezone"></a></p>
<h4>timezone</h4>
<p>验证字段值是否是有效的时区，会根据 PHP 的 <code>timezone_identifiers_list</code> 函数来判断。</p>
<p><a name="rule-unique"></a></p>
<h4>unique:<em>table</em>,<em>column</em>,<em>except</em>,<em>idColumn</em></h4>
<p>在指定的数据表中，验证字段必须是唯一的。如果没有指定 <code>column</code>，将会使用字段本身的名称。</p>
<p><strong>指定一个特定的字段名称：</strong></p>
<pre><code>'email' =&gt; 'unique:users,email_address'</code></pre>
<p><strong>自定义数据库连接</strong></p>
<p>有时候你可能需要自定义一个连接，来通过 Validator 对数据库进行查找。如上面所示，设置 <code>unique:users</code> 作为验证规则，通过默认数据库连接来做数据库查找。如果要重写验证规则，可在指定的连接的表单名称后面加上「.」：</p>
<pre><code>'email' =&gt; 'unique:connection.users,email_address'</code></pre>
<p><strong>强迫 Unique 规则忽略指定 ID：</strong></p>
<p>有时候，你希望在验证字段时对指定 ID 进行忽略。例如，在「更新个人资料」页面会包含用户名、邮箱等字段。这时你会想要验证更新的 e-mail 值是否为唯一的。如果用户仅更改了名称字段而不是 e-mail 字段，就不需要抛出验证错误，因为此用户已经是这个 e-mail 的拥有者了。假设用户提供的 e-mail 已经被其他用户使用，则需要抛出验证错误。若要用指定规则来忽略用户 ID，则应该把要发送的 ID 当作第三个参数：</p>
<pre><code>'email' =&gt; 'unique:users,email_address,'.$user-&gt;id</code></pre>
<p>如果你的数据表使用的主键名称不是 <code>id</code>，那么你可以在第四个参数中来指定它：</p>
<pre><code>'email' =&gt; 'unique:users,email_address,'.$user-&gt;id.',user_id'</code></pre>
<p><strong>增加额外的 Where 语句：</strong></p>
<p>你也可以指定更多的条件到「where」查询语句：</p>
<pre><code>'email' =&gt; 'unique:users,email_address,NULL,id,account_id,1'</code></pre>
<p>上述规则中，只有 <code>account_id</code> 为 <code>1</code> 的数据列会被包含在 unique 规则的验证。</p>
<p><a name="rule-url"></a></p>
<h4>url</h4>
<p>根据 PHP 的 <code>filter_var</code> 函数来验证字段是否符合 URL 格式。</p>
<p><a name="conditionally-adding-rules"></a></p>
<h2>按条件增加规则</h2>
<p>在某些情况下，你可能<strong>只想</strong>在输入数据中有此字段时才进行验证。可通过增加 <code>sometimes</code> 规则到规则列表来实现：</p>
<pre><code>$v = Validator::make($data, [
    'email' =&gt; 'sometimes|required|email',
]);</code></pre>
<p>在上面的例子中，<code>email</code> 字段的验证只会在 <code>$data</code> 数组有此字段时才会进行。</p>
<h4>复杂的条件验证</h4>
<p>有时候你可能希望增加更复杂的验证条件，例如，你可以希望某个指定字段在另一个字段的值超过 100 时才为必填。或者当某个指定字段有值时，另外两个字段要拥有符合的特定值。增加这样的验证条件并不难。首先，利用你熟悉的 <em>static rules</em> 来创建一个 <code>Validator</code> 实例：</p>
<pre><code>$v = Validator::make($data, [
    'email' =&gt; 'required|email',
    'games' =&gt; 'required|numeric',
]);</code></pre>
<p>假设我们有一个专为游戏收藏家所设计的网页应用程序。如果游戏收藏家收藏超过一百款游戏，我们会希望他们来说明下为什么他们会拥有这么多游戏。比如说他们有可能经营了一家二手游戏商店，或者只是为了享受收集的乐趣。为了在特定条件下加入此验证需求，可以在 <code>Validator</code> 实例中使用 <code>sometimes</code> 方法。</p>
<pre><code>$v-&gt;sometimes('reason', 'required|max:500', function($input) {
    return $input-&gt;games &gt;= 100;
});</code></pre>
<p>传入 <code>sometimes</code> 方法的第一个参数是我们要用条件认证的字段名称。第二个参数是我们想使用的验证规则。<code>闭包</code> 作为第三个参数传入，如果其返回 <code>true</code>，则额外的规则就会被加入。这个方法可以轻松的创建复杂的条件式验证。你甚至可以一次对多个字段增加条件式验证：</p>
<pre><code>$v-&gt;sometimes(['reason', 'cost'], 'required', function($input) {
    return $input-&gt;games &gt;= 100;
});</code></pre>
<blockquote>
<p><strong>注意：</strong>传入<code>闭包</code>的 <code>$input</code> 参数是 <code>Illuminate\Support\Fluent</code> 实例，可用来访问你的输入或文件对象。</p>
</blockquote>
<p><a name="custom-validation-rules"></a></p>
<h2>自定义验证规则</h2>
<p>Laravel 提供了许多有用的验证规则。但你可能想自定义一些规则。注册自定义验证规则的方法之一，就是使用 Validator <a href="facades.html">facade</a> 中的 <code>extend</code> 方法，让我们在 <a href="providers.html">服务提供者</a> 中使用这个方法来自定义注册的验证规则：</p>
<pre><code>&lt;?php

namespace App\Providers;

use Validator;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * 启动所有应用程序服务。
     *
     * @return void
     */
    public function boot()
    {
        Validator::extend('foo', function($attribute, $value, $parameters, $validator) {
            return $value == 'foo';
        });
    }

    /**
     * 注册服务提供者。
     *
     * @return void
     */
    public function register()
    {
        //
    }
}</code></pre>
<p>自定义的验证闭包接收四个参数：要被验证的属性名称 <code>$attribute</code>，属性的值 <code>$value</code>，传入验证规则的参数数组 <code>$parameters</code>，及 <code>Validator</code> 实例。</p>
<p>除了使用闭包，你也可以传入类和方法到 <code>extend</code> 方法中：</p>
<pre><code>Validator::extend('foo', 'FooValidator@validate');</code></pre>
<h4>自定义错误消息</h4>
<p>另外你可能还需要为自定义规则来定义一个错误消息。这可以通过使用自定义内联消息数组或是在验证语言包中加入新的规则来实现。此消息应该被放在数组的第一级，而不是被放在 <code>custom</code> 数组内，这是仅针对特定属性的错误消息:</p>
<pre><code>"foo" =&gt; "你的输入是无效的！",

"accepted" =&gt; ":attribute 必须被接受。",

// 其余的验证错误消息...</code></pre>
<p>当你在创建自定义验证规则时，你可能需要定义保留字段来取代错误消息。你可以像上面所描述的那样通过 <code>Validator</code> facade 来使用 <code>replacer</code> 方法创建一个自定义验证器。通过 <a href="providers.html">服务提供者</a> 中的 <code>boot</code> 方法可以实现：</p>
<pre><code>/**
 * 启动所有应用程序服务。
 *
 * @return void
 */
public function boot()
{
    Validator::extend(...);

    Validator::replacer('foo', function($message, $attribute, $rule, $parameters) {
        return str_replace(...);
    });
}</code></pre>
<h4>隐式扩展功能</h4>
<p>默认情况下，若有一个类似 <a href="validation.html#rule-required"><code>required</code></a> 这样的规则，当此规则被验证的属性不存在或包含空值时，其一般的验证规则（包括自定扩展功能）都将不会被运行。例如，当 <a href="validation.html#rule-integer"><code>integer</code></a> 规则的值为 <code>null</code> 时将不会被运行：</p>
<pre><code>$rules = ['count' =&gt; 'integer'];

$input = ['count' =&gt; null];

Validator::make($input, $rules)-&gt;passes(); // true</code></pre>
<p>如果要在属性为空时依然运行此规则，则此规则必须暗示该属性为必填。要创建一个「隐式」扩展功能，可以使用 <code>Validator::extendImplicit()</code> 方法：</p>
<pre><code>Validator::extendImplicit('foo', function($attribute, $value, $parameters, $validator) {
    return $value == 'foo';
});</code></pre>
<blockquote>
<p><strong>注意：</strong>一个「隐式」扩展功能只会 <em>暗示</em> 该属性为必填。它的实际属性是否为无效属性或空属性主要取决于你。</p>
</blockquote>
		</div>

		<div class="main-footer" style="border-top:1px dashed rgba(0, 0, 0, 0.1);padding-top: 30px;margin-top:30px;margin-bottom: 20px;">
			<div class="prev-next-wrap clearfix">

									<a class="btn btn-primary pull-left btn-inverted" href="testing.html"><i class="fa fa-arrow-left"></i> 测试</a>
				
			    &nbsp;
								    <a class="btn btn-primary pull-right btn-inverted" href="database.html">数据库入门 <i class="fa fa-arrow-right"></i></a>
							</div>
		</div>

	</article>
</div>

	<footer class="main">
		<ul>
			<li class="nav-docs"><a href="../5.4.html">文档</a></li>
<li ><a href="https://news.laravel-china.org/" class="no-pjax">Laravel 资讯</a></li>
<li class="dropdown"><a href="https://laravel-china.org/">Laravel China 社区</a></li>
<li class="nav-forge"><a href="https://laravel-china.org/categories/1">酷工作</a></li>
<li class="nav-docs"><a href="http://lumen.laravel-china.org">Lumen</a></li>
<li class="nav-forge"><a href="https://cs.laravel-china.org/">速查表</a></li>
<li class="nav-forge"><a href="https://laravel-china.org/laravel-tutorial/5.1/about">《Laravel 入门教程》</a></li>
		</ul>
		<p>Laravel is a trademark of Taylor Otwell. Copyright &copy; Taylor Otwell.</p>
		<p class="less-significant">
            <a href="http://jackmcdade.com">
                Designed by<br>
                <svg version="1.1"
	 xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:a="http://ns.adobe.com/AdobeSVGViewerExtensions/3.0/"
	 x="0px" y="0px" width="128.2px" height="28px" viewBox="0 0 128.2 28" enable-background="new 0 0 128.2 28" xml:space="preserve"
	>
<defs>
</defs>
<g>
	<path fill="#c3c3c3" d="M14.2,0.4c0,0.2,0,0.5,0,0.7c0,0.2,0,0.5,0,0.7l-1.4-0.3C12.9,3,13,4.5,13.1,6c0.1,1.5,0,3-0.1,4.5
		c0,0.4-0.1,0.8-0.1,1.2c-0.1,0.4-0.1,0.8-0.3,1.2c-0.1,0.4-0.3,0.7-0.5,1.1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0,1-0.1,2-0.2,2.9c-0.1,1-0.1,1.9-0.2,2.9c0.8,0.2,1.5,0.3,2,0.1c0.6-0.2,1.2-0.5,1.9-1c0.2-0.1,0.2-0.3,0.2-0.5
		c0-0.2,0-0.5,0-0.7c0-0.2,0.1-0.5,0.2-0.6c0.1-0.2,0.3-0.3,0.7-0.4c0.4,0,0.6,0.1,0.7,0.4c0.1,0.3,0.2,0.7,0.2,1.1
		c0,0.5,0,0.9-0.1,1.4c-0.1,0.5-0.1,0.9,0,1.2c-0.5,0-1,0-1.4,0c-0.4,0-0.8,0-1.2,0.1c-0.4,0-0.8,0-1.2,0.1c-0.4,0-0.9,0-1.3,0
		c-0.9,0-1.7,0-2.5,0.1c-0.7,0.1-1.6,0.1-2.4,0.1c-0.2-0.2-0.2-0.4-0.2-0.7c0-0.2,0.1-0.5,0.3-0.6c0.2-0.2,0.3-0.3,0.6-0.3
		c0.2-0.1,0.5,0,0.7,0.1c0.1-2.1,0.2-4.3,0.1-6.5C116.3,5.5,116.3,3.4,116.5,1.2z"/>
</g>
</svg>

            </a>
        </p>
	</footer>

	<script>
		var algolia_app_id      = 'FU55RWGNDN';
		var algolia_search_key  = 'c41c5de31ca55044dbb0bde815d35121';
				var version             = '5.2';
			</script>

	<script id="search_suggestion_template" type="text/template">
	<div class="autocomplete-wrapper">
		{{#_highlightResult.h1}}
		<div class="h1">
			{{{ _highlightResult.h1.value }}}
		</div>
		{{/_highlightResult.h1}}

		<div class="sub-section">
			{{#_highlightResult.h2}}
			<div class="h2">
				<span class="hash">#</span> {{{ _highlightResult.h2.value }}}
			</div>
			{{/_highlightResult.h2}}

			{{#_highlightResult.h3}}
			<div class="h3">
				> {{{ _highlightResult.h3.value }}}
			</div>
			{{/_highlightResult.h3}}

			{{#_highlightResult.h4}}
			<div class="h4">
				> {{{ _highlightResult.h4.value }}}
			</div>
			{{/_highlightResult.h4}}
		</div>

		{{#_highlightResult.content}}
		<div class="content">
			{{{ _highlightResult.content.value }}}
		</div>
		{{/_highlightResult.content}}
	</div>
</script>

<script id="search_empty_template" type="text/template">
	<div class="autocomplete-wrapper empty">
		<div class="h2">We didn't find any result for "{{query}}". Sorry!</div>
	</div>
</script>

<script id="search_footer_template" type="text/template">
	<div class="footer">
		<a target="_blank" href="https://www.algolia.com/referrals/5a08e6a4/join">
			<img width="50" src="/docs/assets/img/algolia-logo.png">
			<div class="powered">powered by</div>
			<div style="clear: both"></div>
		</a>
	</div>
</script>

	<script src="../../build/assets/js/laravel-db513c8174.js"></script>
	<script src="../../assets/js/viewport-units-buggyfill.js"></script>

	<script>window.viewportUnitsBuggyfill.init();</script>
    <script>
          ga('create', 'UA-53903425-7', 'auto');
          ga('send', 'pageview');
    </script>
</body>
</html>
